package com.zxy.supplier_system.server.controller

import com.zxy.supplier_system.server.entity.Authority
import com.zxy.supplier_system.server.service.GoodsBrandGroupService
import com.zxy.supplier_system.server.utils.IntIdAndName
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.web.bind.annotation.*

@RequestMapping("goodsBrandGroups")
@RestController
class GoodsBrandGroupController(
    private val goodsBrandGroupService: GoodsBrandGroupService
) {

    data class QueryGoodsBrandGroupsRequest(
        val name: String?,
    )

    @HasAuthority(Authority.货品_品牌分组_查询)
    @GetMapping(params = ["page"])
    fun queryGoodsBrandGroups(pageable: Pageable, queryGoodsBrandGroupsRequest: QueryGoodsBrandGroupsRequest): Page<QueryGoodsBrandGroupsResponse> {
        return this.goodsBrandGroupService.queryGoodsBrandGroups(pageable,queryGoodsBrandGroupsRequest)
    }

    data class QueryGoodsBrandGroupsResponse(
        val name:String,
        val id:Int,
        val brandAmount:Int
    )

    data class UpdateGoodsBrandGroupRequest(
        val name: String,
    )

    @HasAuthority(Authority.货品_品牌分组_修改)
    @PutMapping("{id}")
    fun updateGoodsBrand(@PathVariable id:Int,@RequestBody updateGoodsBrandGroupRequest: UpdateGoodsBrandGroupRequest){
        this.goodsBrandGroupService.updateGoodsBrandGroup(id,updateGoodsBrandGroupRequest)
    }

    @HasAuthority(Authority.货品_品牌分组_新增)
    @PostMapping
    fun createGoodsBrand(@RequestBody updateGoodsBrandGroupRequest: UpdateGoodsBrandGroupRequest){
        this.goodsBrandGroupService.createGoodsBrandGroup(updateGoodsBrandGroupRequest)
    }

    @DeleteMapping("{id}")
    fun deleteGoodsBrand(@PathVariable id:Int){
        this.goodsBrandGroupService.deleteGoodsBrandGroup(id)
    }

    @GetMapping
    fun getAllGoodsBrandGroups():List<IntIdAndName>{
        return this.goodsBrandGroupService.getAllGoodsBrandGroups()
    }

}